package updown.domain;

import com.mysql.cj.util.StringUtils;
import lombok.Data;

/**
 * <p>Title: com.damai.downupservice.domain </p>
 * <p>Description:updown: -  </p>
 *
 * @Author:jiangkaixin
 * @Date:2021/11/6
 * @Version: 1.0
 */
@Data
public class ServiceMapVo {
    private String serviceName;
    private String serverHostList;
    private String jarVersionInfo;
    private String lastRestartTime;
    private String localFilePath;
    private String originalFileName;
    private String scheduleTime;
    private String taskId;

    /**
     * 定时任务：把jar 绝对路径，转化成 originalFileName 和 jarVersionInfo
     * localFilePath:/opt/app/provider-version1.jar
     */
    public void scheduleTask() {
        if (!StringUtils.isNullOrEmpty(localFilePath)) {
            try {
                String[] split = localFilePath.split("/");
                String fileName = split[split.length - 1];
                this.originalFileName = fileName;
                String withoutJar = fileName.substring(0, fileName.indexOf("."));
                String[] dotSplit = withoutJar.split("-");
                this.jarVersionInfo = dotSplit[dotSplit.length-1];
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
